<?php

//UMA new
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ScoreRank extends Model
{
    protected $fillable = [
        'min_score',
        'max_score',
        'min_interests',
        'max_interests',
        'score_rank',
        'median_interests',
        'message'
    ];

        
    /**
     * 根据积分获取等级
     * スコアに応じてレベルを取得
     * @param object $query
     * @param  int $score
     * @return query builder
     */
    public function scopeLevel($query, $score)
    {
        return $query->where([
            ['min_score', '<=', $score],
            ['max_score', '>=', $score],
        ]);
    }

    public function scopeRank($query, $score) {
        return $query->where('min_score', '<=', $score)->orderBy('min_score', 'desc');
    }
}
